package ltd.hanamaki.selenium.study.studySelenium;

import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver.Navigation;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import java.util.concurrent.TimeUnit;

/**
 * @author : FHM
 * @data : 2021/9/3 - 10:56
 */
public class Demo07 {



    static WebDriver driver;
    static Navigation navigate;

    @BeforeClass
    public void setUp() {
        /* 3.1.  */
        /* 注册 火狐浏览器打开的位置 */
        System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
        /* 3.2 注册 驱动 */
        driver = new FirefoxDriver();

        /* 实例化 导航对象 */
        navigate = driver.navigate();

        /*  隐式等待  */
        WebDriver.Timeouts timeouts = driver.manage().timeouts();
        timeouts.implicitlyWait(30, TimeUnit.SECONDS);
        timeouts.setScriptTimeout(10, TimeUnit.SECONDS);
        timeouts.pageLoadTimeout(20, TimeUnit.SECONDS);
    }

    @Test
    public void t() throws InterruptedException {

        driver.get("file:///C:/Users/86130/Desktop/testhtml/exam/House.html");

        WebElement username = driver.findElement(By.name("username"));
        username.clear();
        username.sendKeys("hanamaki");

        /* 固定等待 */
        Thread.sleep(3000);

        /* 显示等待 */
        WebDriverWait webDriverWait = new WebDriverWait(driver, 30);
        WebElement element = webDriverWait.until(new ExpectedCondition<WebElement>() {
            @Override
            public WebElement apply(WebDriver webDriver) {
                return driver.findElement(By.xpath("//input[@name='c2']"));
            }
        });

        element.click();



        WebElement element1 = driver.findElement(By.xpath("//input[@name='c6']"));
        element1.click();


    }



}
